float4x4 World;
float4x4 View;
float4x4 Projection;

float4 LightColor;
float3 LightPosition;

float4 AmbientColor;

float4 SpecularColor;

float SpecularPower;
float SpecularIntensity;

float3 CameraPosition;



struct VertexShaderInput
{
    float4 Position : POSITION0;
	float3 Normal : NORMAL0;
	//float4 Color : COLOR0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 WorldNormal : TEXCOORD0;
	float3 WorldPosition : TEXCOORD1;
	//float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.WorldNormal =  mul(input.Normal, World);
    output.WorldPosition = worldPosition / worldPosition.w;
	
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //calculate per-pixel diffuse
    float3 directionToLight = normalize(LightPosition - input.WorldPosition);
    float diffuseIntensity = saturate( dot(directionToLight, input.WorldNormal));
    float4 diffuse = LightColor * diffuseIntensity;
    
	//calculate Phong components per-pixel
    float3 reflectionVector = normalize(reflect(-directionToLight, input.WorldNormal));
    float3 directionToCamera = normalize(CameraPosition - input.WorldPosition);
    
	//calculate specular component
    float4 specular = SpecularColor * SpecularIntensity * 
                       pow(saturate(dot(reflectionVector, directionToCamera)), 
                           SpecularPower);
      
    //all color components are summed in the pixel shader
    float4 color = specular  + diffuse + AmbientColor;
    color.a = 1.0;
    
    return color;
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
